home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2.0 - Programmer's Utilities Power Pack / Delphi 2.0 Programmer's Utilities Power Pack.iso / a_to_d / delftips / ti2809.asc < prev    next >
Text File  |  1996-09-15  |  2KB  |  122 lines

  1.  
  2.  
  3.  
  4.  
  5.  
  6.  
  7.   PRODUCT  :  Delphi                                 NUMBER  :  2809
  8.   VERSION  :  All
  9.        OS  :  Windows
  10.      DATE  :  May 31, 1995                             PAGE  :  1/2
  11.  
  12.     TITLE  :  Printing the contents of a TMemo or TListbox
  13.  
  14.  
  15.  
  16.  
  17. Q: How can I print all of the lines within a TMemo or TListbox component?
  18.  
  19. A: The function below accepts a TStrings object as a parameter and prints
  20.    out each string to the default printer.  Because it uses a TStrings, the
  21.    function will work with any type of component that contains a 
  22.    TStrings-type property, such as a TDBMemo or TOutline.
  23.  
  24. { Begin code listing }
  25.  
  26. uses Printers;
  27.  
  28. procedure PrintStrings(Strings: TStrings);
  29. var
  30.   Prn: TextFile;
  31.   i: word;
  32. begin
  33.   AssignPrn(Prn);
  34.   try
  35.     Rewrite(Prn);
  36.     try
  37.       for i := 0 to Strings.Count - 1 do
  38.         writeln(Prn, Strings.Strings[i]);
  39.     finally
  40.       CloseFile(Prn);
  41.     end;
  42.   except
  43.     on EInOutError do
  44.       MessageDlg('Error Printing text.', mtError, [mbOk], 0);
  45.   end;
  46. end;
  47.  
  48. { End code listing }
  49.  
  50. To print out the contents of a TMemo or TListbox, use the following
  51. code:
  52.  
  53. PrintStrings(Memo1.Lines);
  54.  
  55.  
  56.  
  57.  
  58.  
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67.  
  68.   PRODUCT  :  Delphi                                 NUMBER  :  2809
  69.   VERSION  :  All
  70.        OS  :  Windows
  71.      DATE  :  May 31, 1995                             PAGE  :  2/2
  72.  
  73.     TITLE  :  Printing the contents of a TMemo or TListbox
  74.  
  75.  
  76.  
  77.  
  78. or
  79.  
  80. PrintStrings(Listbox1.Items);
  81.  
  82.  
  83.  
  84.  
  85.  
  86.  
  87.  
  88.  
  89.  
  90.  
  91.  
  92.  
  93.  
  94.  
  95.  
  96.  
  97.  
  98.  
  99.  
  100.  
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107.  
  108.  
  109.  
  110.  
  111.  
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118. DISCLAIMER: You have the right to use this technical information
  119. subject to the terms of the No-Nonsense License Statement that
  120. you received with the Borland product to which this information
  121. pertains.
  122.